<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input placeholder="输入姓名" id="d1">
<input placeholder="输入年龄" id="d2">
<input placeholder="输入工资" id="d3">
<button onclick="add()">添加</button>
<hr>
<table border="1" >
  <caption>员工列表</caption>
    <tr>
        <th>姓名</th>
        <th>年龄</th>
        <th>工资</th>
    </tr>

</table >

<script>
  function add(){
    var arr=[];
    //获取数据
    let name=document.getElementById('d1').value;
    let age=document.getElementById('d2').value;
    let money=document.getElementById('d3').value;
    //验证数据
    if(name==''||age==''||money==''){alert('请填写完整信息'); return;}
    //创建tr td
    let tr=document.createElement('tr');
    let td1=document.createElement('td');
    let td2=document.createElement('td');
    let td3=document.createElement('td');
    //添加数据
    td1.innerHTML=name;
    td2.innerHTML=age;
    td3.innerHTML=money;
    tr.append(td1,td2,td3);
    //添加ta
    let tb=document.querySelector('table');
    //tr添加进ta
    tb.append(tr);
    //清空数据
    document.getElementById('d1').value='';
    document.getElementById('d2').value='';
    document.getElementById('d3').value='';
    //添加数据进数组`
    arr.push({
      name:name,
      age:age,
      money:money
    })

  }
</script>
</body>
</html>